/*
ID:luongho3
LANG:JAVA
TASK:numtri
 */
package usaco.training.chap1.sec5;

import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;

public class numtri {
	
	static int N;
	static int[][] m;

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("numtri.in"));
		PrintStream ps = new PrintStream(new File("numtri.out"));
		System.setOut(ps);
		
		N = scanner.nextInt();
		m = new int[N][N];
		int max = 0;
		for (int i=0;i<N;++i) {
			for (int j=0;j<=i;++j) {
				m[i][j] = scanner.nextInt();
				if (i==0 && j == 0) {
					continue;
				}
				else if (j==0) {
					m[i][j] += m[i-1][j];
				}
				else if (i==j) {
					m[i][j] += m[i-1][j-1];
				}
				else {
					m[i][j] += Math.max(m[i-1][j], m[i-1][j-1]);
				}
				if (i==N-1) {
					if (m[i][j] > max) {
						max = m[i][j];
					}
				}
			}
		}
		System.out.println(max);
	}

}
